﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThanhTu.GNC.Media.KQXS.DataAccess.DAL;

namespace WebUI.Admin.UserControls
{
    public partial class ActionProvince : System.Web.UI.UserControl
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            int pageIndex = 1;
            try
            {
                pageIndex = int.Parse(Request.QueryString["p"].ToString());
            }
           catch { }
            try
           {
                int totalRow =0;
                ProvinceDAL province = new ProvinceDAL();
                RepeaterProvince.DataSource = province.SelectAll_page(pageIndex,10, ref totalRow);
                RepeaterProvince.DataBind();
                NHPagingControl1.TotalPage =  (totalRow % 10 == 0) ? totalRow / 10 : (totalRow / 10 + 1);
           }
            catch (Exception ex)
            {
                Response.Write("load Province Errorr:" + ex);
            }
            finally
            {

            }
        
        }

        protected void RepeaterProvince_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ProvinceDAL province = new ProvinceDAL();
                int checkDel = province.delete(e.CommandName);
                if (checkDel > 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('XÓA TỈNH Thành công);", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('LỖI,XIN VUI LÒNG THỬ LẠI);", true);
                }
            }
        }

     
    }
}